﻿using CentralVacuum.Common;
using CentralVacuum.Properties;
using CentralVacuum.Keyboard;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CentralVacuum.Froms
{
    public partial class FLogin : UIForm
    {
        public IniFile ini;
        public FLogin()
        {
            InitializeComponent();
            ini = new IniFile(@"C:\FangYuanData\Setting.ini");
        }

        private void uiSymbolButton1_Click(object sender, EventArgs e)
        {
            string LoginPassword = ini.ReadString("Login", "LoginPassword", "");
            if (uiTextBox2.Text == "admin" && uiTextBox1.Text == LoginPassword)
            {
                Global.IsLogin = 1;
                if (Settings.Default.Language == 0)  // 中文
                {
                    UIMessageTip.ShowOk("登录成功!");
                }
                else if (Settings.Default.Language == 1) // 英文
                {
                    UIMessageTip.ShowOk("Login successful!");
                }
                Global.LogNet.WriteInfo(this.Name.ToString(), "登录成功!");
                Close();
            }
            else if (uiTextBox2.Text == "admin" && uiTextBox1.Text == "109109")//打开授权画面窗口
            {
                Global.IsLogin = 2;//连接到授权的权限通道
                if (Settings.Default.Language == 0)  // 中文
                {
                    UIMessageTip.ShowOk("登陆许可证授权!");
                }
                else if (Settings.Default.Language == 1) // 英文
                {
                    UIMessageTip.ShowOk("Login License Authorization!");
                }
                Global.LogNet.WriteInfo(this.Name.ToString(), "登陆许可证授权!");
                Close();
            }
            else if (uiTextBox2.Text == "admin" && uiTextBox1.Text == "654321")//打开授权画面窗口
            {
                Global.IsLogin = 3;//连接到锁机设置
                if (Settings.Default.Language == 0)  // 中文
                {
                    UIMessageTip.ShowOk("登陆产能授权!");
                }
                else if (Settings.Default.Language == 1) // 英文
                {
                    UIMessageTip.ShowOk("Login Yield Authorization!");
                }
                Global.LogNet.WriteInfo(this.Name.ToString(), "登陆产能授权!");
                Close();
            }
            else
            {
                Global.IsLogin = 0;
                if (Settings.Default.Language == 0)  // 中文
                {
                    ShowErrorTip("用户名或者密码错误!");
                }
                else if (Settings.Default.Language == 1) // 英文
                {
                    ShowErrorTip("Wrong username or password!");
                }
            }
        }

        private void uiSymbolButton2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void uiTextBox1_Enter(object sender, EventArgs e)
        {
            KeyboardClass.OpenNumberBoard((UITextBox)sender);
            uiSymbolButton2.Focus();
        }

        private void FLogin_Load(object sender, EventArgs e)
        {
            
        }
    }
}
